package org.dawnframework.beans.factory.support;

import org.dawnframework.beans.factory.config.BeanDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 默认Bean工程
 * @author baiml
 * @since 0.1
 */
public class DefaultableListBeanFactory implements   BeanDefinitionRegistry {
    private Logger logger = LoggerFactory.getLogger(DefaultableListBeanFactory.class);

    /** BeanDefinition cache **/
    private final Map<String, BeanDefinition> beanDefinitionMap = new ConcurrentHashMap<String, BeanDefinition>();


    @Override
    public BeanDefinition getBeanDefinition(String beanName) {

        return beanDefinitionMap.get(beanName);
    }

    @Override
    public void removeBeanDeinition(String beanName) {
     if(beanDefinitionMap.containsKey(beanName)){
         beanDefinitionMap.remove(beanName);
     }
     if(logger.isTraceEnabled()){
         logger.trace("DefaultListFactory.removeBeanDeinition beanName{} is removed!",beanName);
     }
    }

    @Override
    public void registerBeanDefinition(String beanName, BeanDefinition beanDefinition) {
        beanDefinitionMap.put(beanName,beanDefinition);
    }
}
